import traceback

import requests
from lxml.html import etree
import time



def get_find_str_list(find_str):
    headers = {
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "Host": "bulletin.cebpubservice.com",
        "sec-ch-ua": '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
        "sec-ch-ua-mobile": "?0",
        "Sec-Fetch-User": "?1",
        "Upgrade-Insecure-Requests": "1",

        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"

    }
    base_url = ''
    url = 'https://bulletin.cebpubservice.com/xxfbcmses/search/bulletin.html?searchDate=1996-05-31&dates=300&categoryId=88&industryName=&area=&status=&publishMedia=&sourceInfo=&showStatus=&word=\
    {}'.format(find_str)

    # url中的时间格式有问题1996？？
    ret = requests.get(url=url,headers=headers,verify=False)
    ret.encoding = ret.apparent_encoding
    # print(ret.text)
    html = etree.HTML(ret.text)
    ret = html.xpath('//table[@class="table_text"]//tr')
    infos_list = []
    for item in ret:
        try:
            info = item.xpath('.//a//text()')
            if info:
                info_list = item.xpath('.//text()')
                info_list = [i for i in [i.strip() for i in info_list] if i != '']
                print(info_list)
                infos_list.append(info_list)
        except Exception as e:
            traceback.print_exc()
            pass
    return infos_list

# find_str = "伊春农商银行2021年6家网点网点装修改造工程招标公告"
# get_find_str_list(find_str)
find_str = ['北京生物制品研究所有限责任公司质量检定用多功能酶标仪采购项目谈判采购公告',
            '关于西安电子科技大学杭州研究院过渡期学生工位创客休闲区家具采购项目交易公告',
            '上海江南船舶管业有限公司起重机更换项目招标公告',
            '多功能磁性光学测量系统采购国际招标公告(2)',
            '洛阳市“西工小街”东街夜市招商托管项目竞争性磋商公告']
for i in range(4):
    get_find_str_list(find_str[i])
    time.sleep(2*60)





